import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutterapp/entities/assets_entities.dart';

class MarkDownPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _MarkDownState();
}

class _MarkDownState extends State<MarkDownPage> {
  @override
  Widget build(BuildContext context) {
    MarkdownEntity _entity = ModalRoute.of(context).settings.arguments;
    print(_entity.src);
    return Scaffold(
      appBar: AppBar(
        title: Text(_entity.title),
      ),
      body: FutureBuilder(
        future: rootBundle.loadString(_entity.src),
        builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
          print(snapshot.hasData);
          print(snapshot.data);
          if (snapshot.hasData) {
            return Markdown(data: snapshot.data);
          } else {
            return Center(
              child: CircularProgressIndicator(),
            );
          }
        },
      ),
    );
  }
}
